package com.set.hashset;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;

public class Employee implements Comparable<Employee>{
int id;
String name;
Employee(int id,String name){
	this.id=id;
	this.name=name;
}
public int hashCode(){
	String id1=Integer.toString(id);
	String name1=name;
	int hash1=id1.hashCode();
	int hash2=name1.hashCode();
	int hash=hash1+hash2;
	return hash;
}
public boolean equals(Object obj){
	Employee emp=(Employee)obj;
	
	return this.id==emp.id && this.name==emp.name;
}
public String toString(){
	return id+"\t"+name;
}
public static void main(String[] args) {
	HashSet hs=new HashSet();
	hs.add(new Employee(2, "suresh"));
	hs.add(new Employee(1, "gulam"));
	hs.add(new Employee(1, "gulam"));
	hs.add(new Employee(4, "sri"));
	hs.add(new Employee(5, "avinash"));
	hs.add(new Employee(3, "shashi"));
	System.out.println(hs);
	
	Iterator itr=hs.iterator();
	while(itr.hasNext()){
		System.out.println(itr.next());
	}
	
}
@Override
public int compareTo(Employee o) {
	
	return this.id-o.id;
}
}
